﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.Text;

namespace G.BI
{
    public class BIClient
    {
        private const string url = "http://dagehaoshuang.31.cvod.net/APP.ashx";
        public static void SendEvent(BaseEvent e, Action<string> callback)
        {
            G.Net.HttpPost get = new Net.HttpPost(url);
            Dictionary<string, string> dic = new Dictionary<string, string>();

            dic.Add("action", "addevent");
            dic.Add("appkey", BIConfig.APPKey);
            dic.Add("eventid", e.EventID.ToString());
            dic.Add("eventcontent", e.GetSerializaString());
            var sortedParamsBuilder = new StringBuilder();
            foreach (var pair in dic)
            {
                sortedParamsBuilder.Append(string.Format("{0}={1}&", pair.Key, HttpUtility.UrlEncode(pair.Value)));
            }
            get.PostData = sortedParamsBuilder.ToString().GetBytes();
            get.Request((s, msg) =>
            {
                callback(msg);
            });
        }
    }
}
